package register

import (
	"context"

	"server-go/api/reward/internal/svc"
	"server-go/api/reward/internal/types"
	"server-go/rpc/reward/types/reward"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoRegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDoRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoRegisterLogic {
	return &DoRegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DoRegisterLogic) DoRegister(req *types.DoRegisterInput) (resp *types.DoRegisterOutput, err error) {
	resp = new(types.DoRegisterOutput)
	res, err := l.svcCtx.RewardRpc.DoRegister(l.ctx, &reward.DoRegisterInput{
		Agreement: req.AgreeMent,
		Captcha:   req.Captcha,
		Password:  req.PassWord,
		Confirm:   req.Confirm,
		Email:     req.Email,
		Gender:    req.Gender,
		Intro:     req.Intro,
		Nickname:  req.NickName,
	})
	if err != nil {
		return resp, err
	}
	resp.Status = 200
	resp.Message = &types.DoRegister{
		UserName:        res.Username,
		RegisterSuccess: res.RegisterSuccess,
		CaptchaError:    res.CaptchaError,
		EmailError:      res.EmailError,
	}
	return resp, nil
}
